package com.exampl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.exampl.dao.EmployeeDao;
import com.exampl.domain.Employee;
import com.exampl.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeDao, Employee> implements EmployeeService {

    @Autowired
    private EmployeeDao employeeDao;

    @Override
    public IPage<Employee> getPage(Integer currentPage, Integer pageSize, String name) {
        IPage<Employee> page = new Page<Employee>(currentPage, pageSize);
        LambdaQueryWrapper<Employee> lqw = new LambdaQueryWrapper<Employee>();
        // 模糊查询，用于搜索员工，会自动添加 % 通配符
        lqw.like(name != null, Employee::getName, name);
        // 添加排序条件，最后修改的放在前面
        lqw.orderByDesc(Employee::getUpdateTime);
        employeeDao.selectPage(page, lqw);
        return page;
    }
}
